
///
/// This is the common include file with all shared stuff
///

#ifndef COMMON_H
#define COMMON_H

#define TFTP_MAX_SIZE 512
#define TFTP_PORT 50000 
#define TFTP_PORT_STR "50000"
#define SOCKET_TYPE SOCK_DGRAM
#define STDIN fileno(stdin)
#define MSG_BUF_SIZE 1024
#define PROTOCOL_VERSION 2
#define MAX_CHAT_TEXT_SIZE 512
#define CLIENT_COUNT_BYTES 2

typedef enum
{
	NAK_TYPE_CLIENT_COUNT = 0,
	NAK_TYPE_USERNAME

} NAK_TYPE;

typedef enum
{
	HEADER_TYPE_NULL = 0,

	//mandatory types
	HEADER_TYPE_LEAVE,
	HEADER_TYPE_JOIN,
	HEADER_TYPE_FWD,
	HEADER_TYPE_SEND,
	
	//bonus types
	HEADER_TYPE_NAK,
	HEADER_TYPE_OFFLINE,
	HEADER_TYPE_ACK,
	HEADER_TYPE_ONLINE,

	HEADER_TYPE_MAX

} HEADER_TYPE;

typedef enum
{
	ATTR_TYPE_NULL = 0,
	ATTR_TYPE_REASON,
	ATTR_TYPE_USERNAME,
	ATTR_TYPE_CLIENT_COUNT,
	ATTR_TYPE_MESSAGE,
	ATTR_TYPE_MAX

} ATTR_TYPE;

#define HEADER_SIZE 4
#define ATTR_SIZE 4

typedef struct
{
#ifdef B16ENDIAN
	unsigned int version	: 9;
	unsigned int type		: 7;
#else
	unsigned int type		: 7;
	unsigned int version	: 9;
#endif
	unsigned int length		: 16;

} __attribute__((packed)) StructHeader;

typedef struct
{
	unsigned int type	: 16;
	unsigned int length	: 16;

} __attribute__((packed)) StructAttribute;

#endif
